﻿using System;
using System.Collections.Generic;
using System.Text;
using System.Configuration;
using System.IO;
using System.Reflection;

namespace ColdSun.Commons.Configs
{
    public class CommonConfigs
    {
        public static Boolean IsDebugMode
        {
            get
            {
                try
                {
                    return Convert.ToBoolean(ConfigurationManager.AppSettings["IsDebugMode"]);
                }
                catch {}
                return false;
            }
        }

        private static string GetFullFileName(string fileName)
        {
            if (string.IsNullOrEmpty(fileName) || fileName.Contains(":\\"))
            {
                return fileName;
            }
            if (!fileName.StartsWith("\\"))
            {
                fileName = "\\" + fileName;
            }
            string fullFileName = Path.GetDirectoryName(Assembly.GetExecutingAssembly().GetName().CodeBase) + fileName;
            if (fullFileName.StartsWith("file:\\"))
            {
                fullFileName = fullFileName.Remove(0, "file:\\".Length);
            }
            return fullFileName;
        }

        public static int OriginalHeaderRowIndex { get { return 11;} }
        public static string DeleteOriginalColumnIndexs { get { return "R,P,O"; } }
        public static string InsertOriginalColumnIndexs { get { return "L,Q,R"; } }
        public static string ExportColumnWidths
        {
            get
            {
                string value = ConfigurationManager.AppSettings["ExportColumnWidths"];
                if (!string.IsNullOrEmpty(value))
                {
                    return value;
                }
                return "A:9,B:32,C:20,D:16,E:16,F:16,G:16";
            }
        }
        public static string ExportColumnIndexs
        {
            get
            {
                string value = ConfigurationManager.AppSettings["ExportColumnIndexs"];
                if (!string.IsNullOrEmpty(value))
                {
                    return value;
                }
                return "A,B,C,D,E,F,G";
            }
        }
        public static string ExportDateTimeFormatInFileName
        {
            get
            {
                string value = ConfigurationManager.AppSettings["ExportDateTimeFormatInFileName"];
                if (!string.IsNullOrEmpty(value))
                {
                    return value;
                }
                return "yyyy MM dd";
            }
        }
        public static string VLOOKUPData
        {
            get
            {
                string value = ConfigurationManager.AppSettings["VLOOKUPData"];
                if (!string.IsNullOrEmpty(value))
                {
                    return value;
                }
                return "=VLOOKUP(D{0},Data!$D$2:$T$607,15,0";
            }
        }

        public static string ExportTemplateFile
        {
            get
            {
                string file = ConfigurationManager.AppSettings["ExportTemplateFile"];
                if (!string.IsNullOrEmpty(file))
                {
                    return file;
                }
                return "";
            }
        }
        public static string ExportExcelTemplateFile
        {
            get
            {
                string file = ConfigurationManager.AppSettings["ExportExcelTemplateFile"];
                if (!string.IsNullOrEmpty(file))
                {
                    return file;
                }
                return "";
            }
        }
        public static string ExportWordTemplateFile
        {
            get
            {
                string file = ConfigurationManager.AppSettings["ExportWordTemplateFile"];
                if (!string.IsNullOrEmpty(file))
                {
                    return file;
                }
                return "";
            }
        }
        public static string ExportWordFileName
        {
            get
            {
                string file = ConfigurationManager.AppSettings["ExportWordFileName"];
                if (!string.IsNullOrEmpty(file))
                {
                    return file;
                }
                return "ReportTemplate_#Name#_#ID#_#Date#.doc";
            }
        }
        public static string ExportExcelFileName
        {
            get
            {
                string file = ConfigurationManager.AppSettings["ExportExcelFileName"];
                if (!string.IsNullOrEmpty(file))
                {
                    return file;
                }
                return "ReportTemplate_#Name#_#ID#_#Date#.xlsx";
            }
        }
        public static bool ExportExcelIsSave
        {
            get
            {
                try
                {
                    return Convert.ToBoolean(ConfigurationManager.AppSettings["ExportExcelIsSave"]);
                }
                catch { }
                return false;
            }
        }

        public static string ExportExcelTempFileName
        {
            get
            {
                string file = ConfigurationManager.AppSettings["ExportExcelTempFileName"];
                if (!string.IsNullOrEmpty(file))
                {
                    return file;
                }
                return "ExportExcelTempFile_#Date#.xlsx";
            }
        }

        public static string DepartmentFile
        {
            get
            {
                string file = ConfigurationManager.AppSettings["DepartmentFile"];
                if (!string.IsNullOrEmpty(file))
                {
                    return file;
                }
                return "";
            }
        }

        public static string DefaultExportFolder
        {
            get
            {
                string file = ConfigurationManager.AppSettings["DefaultExportFolder"];
                if (!string.IsNullOrEmpty(file))
                {
                    return file;
                }
                return "";
            }
        }

        public static string DefaultOriginalFile
        {
            get
            {
                string file = ConfigurationManager.AppSettings["DefaultOriginalFile"];
                if (!string.IsNullOrEmpty(file))
                {
                    return file;
                }
                return "";
            }
        }

        public static string DefaultFollowingFile
        {
            get
            {
                string file = ConfigurationManager.AppSettings["DefaultFollowingFile"];
                if (!string.IsNullOrEmpty(file))
                {
                    return file;
                }
                return "";
            }
        }

        public static string DefaultExportDepartments
        {
            get
            {
                return ConfigurationManager.AppSettings["DefaultExportDepartments"];
            }
        }

        public static string ExportAccountTypes
        {
            get
            {
                return ConfigurationManager.AppSettings["ExportAccountTypes"];
            }
        }

        #region Service Desk User
        public static string ServiceDeskUserExportFolder
        {
            get
            {
                return ConfigurationManager.AppSettings["ServiceDeskUser_ExportFolder"];
            }
        }

        #region OP
        public static string ServiceDeskUserOPOriginalExcelFile
        {
            get
            {
                return ConfigurationManager.AppSettings["ServiceDeskUser_OPOriginalExcelFile"];
            }
        }

        public static string ServiceDeskUserOPWordTemplateFile
        {
            get
            {
                return ConfigurationManager.AppSettings["ServiceDeskUser_OPWordTemplateFile"];
            }
        }

        public static string ServiceDeskUserOPInfoFile
        {
            get
            {
                return ConfigurationManager.AppSettings["ServiceDeskUser_OPInfoFile"];
            }
        }

        public static string ServiceDeskUserOPExportFile
        {
            get
            {
                return ConfigurationManager.AppSettings["ServiceDeskUser_OPExportFile"];
            }
        }
        #endregion

        #region IT
        public static string ServiceDeskUserITWordTemplateFile
        {
            get
            {
                return ConfigurationManager.AppSettings["ServiceDeskUser_ITWordTemplateFile"];
            }
        }

        public static string ServiceDeskUserITInfoFile
        {
            get
            {
                return ConfigurationManager.AppSettings["ServiceDeskUser_ITInfoFile"];
            }
        }

        public static string ServiceDeskUserITExportFile
        {
            get
            {
                return ConfigurationManager.AppSettings["ServiceDeskUser_ITExportFile"];
            }
        }
        #endregion
        #endregion

        #region Insurance
        public static string InsuranceOriginalFile
        {
            get
            {
                return ConfigurationManager.AppSettings["Insurance_OriginalFile"];
            }
        }

        public static string InsuranceExportFolder
        {
            get
            {
                return ConfigurationManager.AppSettings["Insurance_ExportFolder"];
            }
        }
        
        #region Insurance Fire
        public static string InsuranceFireInfoFile
        {
            get
            {
                return ConfigurationManager.AppSettings["InsuranceFire_InfoFile"];
            }
        }

        public static string InsuranceFireTemplateFile
        {
            get
            {
                return ConfigurationManager.AppSettings["InsuranceFire_TemplateFile"];
            }
        }

        public static string InsuranceFireExportFile
        {
            get
            {
                return ConfigurationManager.AppSettings["InsuranceFire_ExportFile"];
            }
        }
        #endregion

        #region Insurance Incident
        public static string InsuranceIncidentInfoFile
        {
            get
            {
                return ConfigurationManager.AppSettings["InsuranceIncident_InfoFile"];
            }
        }

        public static string InsuranceIncidentTemplateFile
        {
            get
            {
                return ConfigurationManager.AppSettings["InsuranceIncident_TemplateFile"];
            }
        }

        public static string InsuranceIncidentExportFile
        {
            get
            {
                return ConfigurationManager.AppSettings["InsuranceIncident_ExportFile"];
            }
        }
        #endregion
        public static string InsuranceCompanyName(int type)
        {
            return ConfigurationManager.AppSettings[string.Format("InsuranceCompanyName_{0}", type)];
        }

        public static int InsuranceOriginalHeaderRowIndex { get { return 1; } }
        public static int InsuranceTemplateHeaderRowIndex { get { return 6; } }

        public static string InsuranceDateTimeFormatInFileName
        {
            get
            {
                string value = ConfigurationManager.AppSettings["Insurance_DateTimeFormatInFileName"];
                if (!string.IsNullOrEmpty(value))
                {
                    return value;
                }
                return "yyyy MM dd";
            }
        }
        #endregion


        #region Insurance for branch by month
        public static int InsuranceForBranchByMonthBCTHHeaderRowIndex { get { return 1; } }

        public static int InsuranceForBranchByMonthHeaderRowIndex { get { return 256; } }

        public static string InsuranceForBranchByMonthTotalColumn { get { return "I"; } }
        public static string InsuranceForBranchByMonthTotalFeeColumn { get { return "N"; } }

        public static int InsuranceForBranchByMonthBKCPNHCDIndex { get { return 285; } }

        public static string InsuranceForBranchByMonthOriginalFile
        {
            get
            {
                return ConfigurationManager.AppSettings["InsuranceForBranchByMonth_OriginalFile"];
            }
        }

        #region
        public static string InsuranceForBranchByMonthBKCPOfFireTemplateFile
        {
            get
            {
                string value = ConfigurationManager.AppSettings["InsuranceForBranchByMonth_BKCPOfFireTemplateFile"];
                if (string.IsNullOrEmpty(value))
                {
                    value = "Templates\\InsuranceForMonth\\1.BAO HIEM CHAY NO - Bang ke chi phi.xlsx";
                }

                return GetFullFileName(value);
            }
        }

        public static string InsuranceForBranchByMonthBKCPOfIncidentTemplateFile
        {
            get
            {
                string value = ConfigurationManager.AppSettings["InsuranceForBranchByMonth_BKCPOfIncidentTemplateFile"];
                if (string.IsNullOrEmpty(value))
                {
                    value = "Templates\\InsuranceForMonth\\1.BAO HIEM TAI NAN - Bang ke chi phi.xlsx";
                }

                return GetFullFileName(value);
            }
        }
        #endregion

        public static string InsuranceForBranchByMonthBCTHTemplateFile
        {
            get
            {
                return ConfigurationManager.AppSettings["InsuranceForBranchByMonth_BCTHTemplateFile"];
            }
        }

        #region PL06
        public static string InsuranceForBranchByMonthPL06OfBaoMinhTemplateFile
        {
            get
            {
                string value = ConfigurationManager.AppSettings["InsuranceForBranchByMonth_PL06OfBaoMinhTemplateFile"];
                if (string.IsNullOrEmpty(value))
                {
                    value = "Templates\\InsuranceForMonth\\5. Phu luc 6  Mau Bang tong hop bao hiem TNCN - Bao Minh.docx";
                }
                
                return GetFullFileName(value);
            }
        }

        public static string InsuranceForBranchByMonthPL06OfPVITemplateFile
        {
            get
            {
                string value = ConfigurationManager.AppSettings["InsuranceForBranchByMonth_PL06OfPVITemplateFile"];
                if (string.IsNullOrEmpty(value))
                {
                    value = "Templates\\InsuranceForMonth\\5. Phu luc 6  Mau Bang tong hop bao hiem TNCN - PVI.docx";
                }

                return GetFullFileName(value);
            }
        }

        public static string InsuranceForBranchByMonthPL06OfAAATemplateFile
        {
            get
            {
                string value = ConfigurationManager.AppSettings["InsuranceForBranchByMonth_PL06OfAAATemplateFile"];
                if (string.IsNullOrEmpty(value))
                {
                    value = "Templates\\InsuranceForMonth\\5. Phu luc 6  Mau Bang tong hop bao hiem CNSC - AAA.docx";
                }

                return GetFullFileName(value);
            }
        }

        public static string InsuranceForBranchByMonthPL06OfToanCauTemplateFile
        {
            get
            {
                string value = ConfigurationManager.AppSettings["InsuranceForBranchByMonth_PL06OfToanCauTemplateFile"];
                if (string.IsNullOrEmpty(value))
                {
                    value = "Templates\\InsuranceForMonth\\5. Phu luc 6  Mau Bang tong hop bao hiem CNSC - Toan Cau.docx";
                }

                return GetFullFileName(value);
            }
        }
        #endregion

        #region BM02
        public static string InsuranceForBranchByMonthBM02OfBaoMinhTemplateFile
        {
            get
            {
                string value = ConfigurationManager.AppSettings["InsuranceForBranchByMonth_BM02OfBaoMinhTemplateFile"];
                if (string.IsNullOrEmpty(value))
                {
                    value = "Templates\\InsuranceForMonth\\3. BM02 QD TC 005 Mau de nghi thanh toan TNCN - Bao Minh.docx";
                }

                return GetFullFileName(value);
            }
        }

        public static string InsuranceForBranchByMonthBM02OfPVITemplateFile
        {
            get
            {
                string value = ConfigurationManager.AppSettings["InsuranceForBranchByMonth_BM02OfPVITemplateFile"];
                if (string.IsNullOrEmpty(value))
                {
                    value = "Templates\\InsuranceForMonth\\3. BM02 QD TC 005 Mau de nghi thanh toan TNCN - PVI.docx";
                }

                return GetFullFileName(value);
            }
        }

        public static string InsuranceForBranchByMonthBM02OfAAATemplateFile
        {
            get
            {
                string value = ConfigurationManager.AppSettings["InsuranceForBranchByMonth_BM02OfAAATemplateFile"];
                if (string.IsNullOrEmpty(value))
                {
                    value = "Templates\\InsuranceForMonth\\3. BM02 QD TC 005 Mau de nghi thanh toan CNSC - AAA.docx";
                }

                return GetFullFileName(value);
            }
        }

        public static string InsuranceForBranchByMonthBM02OfToanCauTemplateFile
        {
            get
            {
                string value = ConfigurationManager.AppSettings["InsuranceForBranchByMonth_BM02OfToanCauTemplateFile"];
                if (string.IsNullOrEmpty(value))
                {
                    value = "Templates\\InsuranceForMonth\\3. BM02 QD TC 005 Mau de nghi thanh toan CNSC - Toan Cau.docx";
                }

                return GetFullFileName(value);
            }
        }
        #endregion
        public static string InsuranceForBranchByMonthBM02TemplateFile
        {
            get
            {
                return ConfigurationManager.AppSettings["InsuranceForBranchByMonth_BM02TemplateFile"];
            }
        }

        #region Insurance Fire

        public static string InsuranceForBranchByMonthExportFile
        {
            get
            {
                return ConfigurationManager.AppSettings["InsuranceForBranchByMonth_ExportFile"];
            }
        }

        public static string InsuranceForBranchByMonthExportFolder
        {
            get
            {
                return ConfigurationManager.AppSettings["InsuranceForBranchByMonth_ExportFolder"];
            }
        }
        public static string InsuranceForBranchByMonthSumColumns
        {
            get
            {
                string value = ConfigurationManager.AppSettings["InsuranceForBranchByMonthFire_SumColumns"];
                if (string.IsNullOrEmpty(value))
                {
                    value = "I,N";
                }
                return value;
            }
        }

        public static string InsuranceForBranchByMonthSumRowColor
        {
            get
            {
                string value = ConfigurationManager.AppSettings["InsuranceForBranchByMonthFire_SumRowColor"];
                if (string.IsNullOrEmpty(value))
                {
                    value = "LightGreen";
                }
                return value;
            }
        }
        #endregion
       
        #endregion

        #region Update Address
        public static string UpdateAddressExportFolder
        {
            get
            {
                return ConfigurationManager.AppSettings["UpdateAddress_ExportFolder"];
            }
        }

        public static string UpdateAddressOriginalExcelFile
        {
            get
            {
                return ConfigurationManager.AppSettings["UpdateAddress_OriginalExcelFile"];
            }
        }

        public static string UpdateAddressExportFile
        {
            get
            {
                return ConfigurationManager.AppSettings["UpdateAddress_ExportFile"];
            }
        }

        public static string UpdateAddressUpdateColumns
        {
            get
            {
                return ConfigurationManager.AppSettings["UpdateAddress_UpdateColumns"];
            }
        }

        public static string UpdateAddressHeaderRowIndex
        {
            get
            {
                return ConfigurationManager.AppSettings["UpdateAddress_HeaderRowIndex"];
            }
        }

        public static string UpdateAddressInfoFile
        {
            get
            {
                return ConfigurationManager.AppSettings["UpdateAddress_InfoFile"];
            }
        }
        #endregion
    }
}
